package me.lwn.auth.common;

import java.io.Serializable;

public class HttpMsg<T> implements Serializable {

    public static final int CODE_SUCCESS = 200;
    public static final int CODE_GENERAL_FAIL = 1001;
    private static final long serialVersionUID = -5987366255505295857L;
    private int code;

    private String message;

    private T data;

    public HttpMsg() {
    }

    public HttpMsg(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> HttpMsg<T> success(String... message) {
        String msg = message.length > 0 ? message[0] : "SUCCESS";
        return new HttpMsg<>(CODE_SUCCESS, msg);
    }

    public static <T> HttpMsg<T> fail(String... message) {
        String msg = message.length > 0 ? message[0] : "FAIL";
        return new HttpMsg<>(CODE_GENERAL_FAIL, msg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
